<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>昵称验证</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }
        
        .container {
            background-color: white;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            padding: 40px;
            width: 100%;
            max-width: 500px;
            transition: transform 0.3s ease;
        }
        
        .container:hover {
            transform: translateY(-5px);
        }
        
        h1 {
            color: #333;
            text-align: center;
            margin-bottom: 10px;
            font-weight: 600;
        }
        
        .description {
            text-align: center;
            color: #666;
            margin-bottom: 30px;
            font-size: 14px;
        }
        
        .form-group {
            margin-bottom: 25px;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: #444;
        }
        
        .input-container {
            position: relative;
            margin-bottom: 5px;
        }
        
        input {
            width: 100%;
            padding: 12px 15px;
            border: 2px solid #e1e5ee;
            border-radius: 8px;
            font-size: 16px;
            transition: all 0.3s ease;
            outline: none;
        }
        
        input:focus {
            border-color: #4a6cf7;
            box-shadow: 0 0 0 3px rgba(74, 108, 247, 0.1);
        }
        
        input.valid {
            border-color: #10b981;
        }
        
        input.invalid {
            border-color: #ef4444;
        }
        
        .tishifu {
            font-size: 14px;
            padding: 8px 12px;
            border-radius: 6px;
            margin-top: 5px;
            transition: all 0.3s ease;
            opacity: 0;
            transform: translateY(-10px);
            height: 0;
            overflow: hidden;
        }
        
        .tishifu.right {
            opacity: 1;
            transform: translateY(0);
            height: auto;
            background-color: #d1fae5;
            color: #065f46;
            border-left: 4px solid #10b981;
        }
        
        .tishifu.wrong {
            opacity: 1;
            transform: translateY(0);
            height: auto;
            background-color: #fee2e2;
            color: #991b1b;
            border-left: 4px solid #ef4444;
        }
        
        .rules {
            background-color: #f9fafb;
            border-radius: 8px;
            padding: 15px;
            margin-top: 20px;
        }
        
        .rules h3 {
            font-size: 15px;
            margin-bottom: 10px;
            color: #374151;
        }
        
        .rules ul {
            list-style-type: none;
            padding-left: 0;
        }
        
        .rules li {
            padding: 5px 0;
            font-size: 14px;
            color: #6b7280;
            display: flex;
            align-items: center;
        }
        
        .rules li::before {
            content: "•";
            color: #4a6cf7;
            font-weight: bold;
            margin-right: 8px;
        }
        
        @media (max-width: 480px) {
            .container {
                padding: 25px;
            }
            
            h1 {
                font-size: 24px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>设置您的昵称</h1>
        <p class="description">请输入2-8个中文字符作为您的昵称</p>
        
        <div class="form-group">
            <label for="username">昵称</label>
            <div class="input-container">
                <input type="text" id="username" class="username" placeholder="请输入昵称">
            </div>
            <div class="tishifu"></div>
        </div>
        
        <div class="rules">
            <h3>昵称规则：</h3>
            <ul>
                <li>只能使用中文字符</li>
                <li>长度在2-8个字符之间</li>
                <li>不支持数字、字母或特殊符号</li>
                <li>不能包含空格</li>
            </ul>
        </div>
    </div>

    <script>
        const usernamePattern = /^[\u4e00-\u9fa5]{2,8}$/;
        const usernameInput = document.getElementById('username');
        const tishifu = document.querySelector('.tishifu');
        
        // 实时验证
        usernameInput.addEventListener('input', function() {
            validateUsername(this.value);
        });
        
        // 失去焦点时验证
        usernameInput.addEventListener('blur', function() {
            validateUsername(this.value);
        });
        
        // 获得焦点时重置样式
        usernameInput.addEventListener('focus', function() {
            this.classList.remove('valid', 'invalid');
            tishifu.classList.remove('right', 'wrong');
        });
        
        function validateUsername(username) {
            // 清除之前的样式
            usernameInput.classList.remove('valid', 'invalid');
            tishifu.classList.remove('right', 'wrong');
            
            // 如果输入为空，不显示任何反馈
            if (username === '') {
                return;
            }
            
            // 验证用户名
            if (usernamePattern.test(username)) {
                // 验证成功
                usernameInput.classList.add('valid');
                tishifu.classList.add('right');
                tishifu.textContent = '恭喜您，昵称输入成功！';
            } else {
                // 验证失败
                usernameInput.classList.add('invalid');
                tishifu.classList.add('wrong');
                
                // 根据错误类型提供具体反馈
                if (username.length < 2) {
                    tishifu.textContent = '昵称太短，请输入至少2个中文字符。';
                } else if (username.length > 8) {
                    tishifu.textContent = '昵称太长，最多只能输入8个中文字符。';
                } else if (!/^[\u4e00-\u9fa5]+$/.test(username)) {
                    tishifu.textContent = '昵称只能包含中文字符，不能包含数字、字母或特殊符号。';
                } else {
                    tishifu.textContent = '昵称错误，请重新输入！';
                }
            }
        }
    </script>
</body>
</html>